World Bank에서 발표한 세계 여러 나라의 각종 지표 데이터를 이용하여 EDA를 진행했습니다.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
import plotly.io as pi
import seaborn as sns
wb_df = pd.read_csv("data.csv")
df.dtypes
wb_df[wb_df["Country Name"] == "Afghanistan"]
각 국가별로 1960년부터 2020년까지 데이터가 주어지되, 년도마다 결측치를 갖는 컬럼이 각각 다른 것으로 보인다. 검증하고자 하는 가설에서 필요한 컬럼의 결측치가 없는 해를 골라 가설을 검증해야 할 듯 보인다.
wb_df.corr()["Mortality rate, infant (per 1,000 live births)"]
plt.figure(figsize=(15, 15))
sns.heatmap(wb_df.corr())
plt.show()
다음과 같이 총 8개의 컬럼 사이에 0.3 이상 양 또는 음의 상관관계가 있음을 확인했다.
cutted_df = wb_df[["Country Name", "year", "Access to electricity (% of population)", "Birth rate, crude (per 1,000 people)", "CPIA gender equality rating (1=low to 6=high)", "Employment in agriculture (% of total employment) (modeled ILO estimate)", "GDP per capita (current US$)", "Literacy rate, adult total (% of people ages 15 and above)", "Mortality rate, infant (per 1,000 live births)", "Rural population (% of total population)","Population, total"]]
cutted_df = cutted_df.sort_values("year", ascending=True)
nadropped_df = cutted_df[(cutted_df["GDP per capita (current US$)"].isna() == False) & (cutted_df["Employment in agriculture (% of total employment) (modeled ILO estimate)"].isna()==False) & (cutted_df["Population, total"].isna()==False)]
fig = px.scatter(nadropped_df,x="Employment in agriculture (% of total employment) (modeled ILO estimate)", y="GDP per capita (current US$)",
animation_frame="year", size="Population, total", animation_group="Country Name", hover_name="Country Name", size_max=60,
range_x=[0, 100], range_y=[100, 130000], log_y=True
)
fig.show()
년도를 가리지 않고 농업종사자 비율이 낮을수록 1인당 GDP가 높은 경향이 나타나는 것을 확인할 수 있다.
nadropped_df = cutted_df[(cutted_df["Literacy rate, adult total (% of people ages 15 and above)"].isna() == False) & (cutted_df["Mortality rate, infant (per 1,000 live births)"].isna()==False) & (cutted_df["Population, total"].isna()==False)]
nadropped_df = nadropped_df[["year", "Country Name", "Literacy rate, adult total (% of people ages 15 and above)", "Mortality rate, infant (per 1,000 live births)", "Population, total"]]
nadropped_df.head(5)
nadropped_df.groupby("year").count()
nadropped_df = nadropped_df[nadropped_df["year"] >= 1990]
fig = px.scatter(nadropped_df,y="Mortality rate, infant (per 1,000 live births)", x="Literacy rate, adult total (% of people ages 15 and above)",
animation_frame="year", size="Population, total", animation_group="Country Name", hover_name="Country Name", size_max=30,
range_x=[0, 100], range_y=[0, 200]
)
fig.show()
년도를 가리지 않고 문해율이 낮을수록 엳아사망률이 높은 경향이 나타나는 것을 확인할 수 있다.
nadropped_df = cutted_df[(cutted_df["Birth rate, crude (per 1,000 people)"].isna() == False) & (cutted_df["CPIA gender equality rating (1=low to 6=high)"].isna()==False)& (cutted_df["Population, total"].isna()==False)]
fig = px.scatter(nadropped_df,y="CPIA gender equality rating (1=low to 6=high)", x="Birth rate, crude (per 1,000 people)",
animation_frame="year", animation_group="Country Name", size="Population, total",hover_name="Country Name", size_max=30,
range_x=[5, 60], range_y=[0, 7]
)
fig.show()
년도를 가리지 않고 출생률이 낮을수록 성평등 등급이 높은 경향이 나타나지만 그 경향이 그리 강하지는 않음을 확인할 수 있다.